<template>
  <div class="main">
    <SkuDetail ref="SkuDetail" class="array" />
    <!-- 文章列表table表单 -->
    <el-card shadow="never" class="card">
      <div slot="header" class="clearfix">
        <el-button type="primary" size="default" @click="add"
          >新增文章</el-button
        >
      </div>
      <el-table
        :data="tableData"
        style="width: 100%"
        max-height="1000"
        v-loading="loading"
        border
      >
        <el-table-column fixed type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column
          prop="province"
          label="展示图片"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <img
              style="width: 100px; height: 100px"
              :src="scope.row.pic"
              alt=""
            />
          </template>
        </el-table-column>

        <el-table-column label="活动时间" width="300" align="center">
          <template slot-scope="scope">
            <div>开始时间： {{ scope.row.promotionEndTime }}</div>
            <div>结束时间： {{ scope.row.promotionStartTime }}</div>
          </template>
        </el-table-column>
        <el-table-column
          width="150"
          label="商品名称"
          prop="name"
          align="center"
        >
        </el-table-column>
        <el-table-column
          width="150"
          label="品牌名称"
          prop="brandName"
          align="center"
        >
        </el-table-column>
        <el-table-column
          width="150"
          label="商品价格"
          prop="price"
          align="center"
        >
        </el-table-column>

        <el-table-column
          width="150"
          label="商品类别"
          prop="productCategoryName"
          align="center"
        >
        </el-table-column>
        <el-table-column
          width="300"
          label="创建时间"
          prop="createTime"
          align="center"
        >
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              @click="deleteRow(scope.row)"
              type="text"
              size="small"
              style="color: red !important"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import marketing from '@/api/marketing.js'
import SkuDetail from './components/SkuDetail.vue'
import mixin from '@/mixins'

export default {
  mixins: [mixin],
  components: {
    SkuDetail,
  },
  data() {
    return {
      searchFrom: {}, //输入框里的对象
      form: {}, //实际搜索要用的表单
      tableData: [], //文章列表数据
      loading: false,
    }
  },
  created() {
    this.getArticleList()
  },
  mounted() {},
  methods: {
    //获取文章列表
    getArticleList() {
      // this.loading = true
      setTimeout(() => {
        marketing.findAllRecommendsApi().then(res => {
          this.tableData = res.data.items
          console.log(this.tableData, 'res')
        })
      })
    },
    //删除文章
    deleteRow(row) {
      console.log(row, '删除')
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        marketing.delRecommendApis(row.recommendId).then(res => {
          if (res.success) {
            console.log(res, 'resss')
            this.$message.success('删除成功')
            this.getArticleList()
          } else {
            this.$message.error(res.message)
          }
        })
      })
    },
    //新增活动
    add() {
      console.log('新增文章')
      this.$refs.SkuDetail.open()
    },
  },
}
</script>

<style lang="scss" scoped>
.main {
  background: #f5f5f5;
  .card {
    width: 96.5%;
    margin: 30px;
  }
}
.condtion {
  background-color: #fff;
  color: #303133;
  font-size: 10px;
}
.users {
  margin-right: 200px;
}
.usered {
  position: relative;
  top: 30px;
}
.el-card__body {
  height: 1200px;
}
</style>